import { submitShopPay} from "../../../api/order";
Page({
  data: {
    amount:'',
    customer_id:'',
    checked: false,
    showState: false
  },
  submit() {
    const { amount,customer_id} = this.data;
    if(!amount){
      my.showToast({
        type: 'fail',
        content: '请输入消费金额',
        duration: 1000,
      });
    }
    submitShopPay({amount:amount,customer_id:customer_id}).then(res => {
      if (res.trade_no) {
        my.tradePay({
          tradeNO: res.trade_no,
          success: (res) => {
            if (res.resultCode == 9000) {
              my.navigateBack();
            } else {
              my.showToast({
                type: 'fail',
                content: '支付失败，请稍后重试',
                duration: 1000,
              });
            }
          }
        });
      }
    })
  },
  checkedChange(e) {
    const { value } = e.detail;
    this.setData({ checked: value });
  },
  openState() {
    this.setData({ showState: true });
  },
  closeModal() {
    this.setData({ showState: false });
  },
  onLoad(options) {
      let optionsa='';
     optionsa = my.getLaunchOptionsSync().query;
    this.setData({ customer_id: optionsa.customer_id });
  },
  onBack(e) {
    this.setData({ amount: e.detail.value })
  },
  onShow() {
  }
});
